Deploying Kanzi applications to Android
Before you can build and deploy Kanzi applications to Android devices, you need to set up the Kanzi build environment for Android and install on your computer the USB device drivers for your Android device. See Installing the Kanzi build environment for Android.
To build and deploy Kanzi applications using the Kanzi 3.6.4 Android platform package, see Building applications using the Kanzi Studio 3.6.4 Android platform package.
Building and deploying Kanzi applications to Android from Kanzi Studio
If your Kanzi application includes a Kanzi Engine plugin, you have to build and deploy your application manually. See Building and deploying Kanzi applications to Android manually.
To build and deploy Kanzi applications using the Kanzi 3.6.4 Android platform package, see Building applications using the Kanzi Studio 3.6.4 Android platform package.
To build and deploy your Kanzi application to Android from Kanzi Studio:
-
If you add content to your application using the Kanzi Engine API, make sure to include that content in the <ProjectName>/configs/android/build.xml file in the
<target name="-pre-compile">
target. For example, to add all .xml and .png files in the <ProjectName>/Application/bin directory use
<target name="-pre-compile">
<echo>Copying assets</echo>
<copy todir="${asset.absolute.dir}">
<fileset dir="${asset.absolute.dir}/../../../../bin">
<include name="**/*.kzb"/>
<include name="**/*.cfg"/>
<include name="**/*.xml"/>
<include name="**/*.png"/>
- Connect your Android device to your computer.
- In Kanzi Studio create or open the project for your Kanzi application and select > Export > Build Android Package.
Kanzi Studio builds the application source code, creates .apk package, and installs the package to your Android device.
Configuring Android builds
You can configure the building of your Kanzi applications for Android using the application configurations in Kanzi Studio. For example, you can set the target architecture, and whether Kanzi should deploy the built package to the attached target device. You can set which application configuration you want to use when you select > Export > Build Android Package in > in the Default Build Configuration property.
- In Kanzi Studio in the Library right-click Applications and select Create Application Configuration.
- In the Properties set the configuration for the Android build.
For example:- Enable the Build Debug Version property to set the build type to debug, instead of the default release build type.
- Disable the Install to Device property if you want to manually install the .apk package to your Android device.
Setting the Java version for Kanzi applications
To set the Java version for your Kanzi applications for Android, add to the Application/configs/platforms/android/build.xml as the first child elements of the top level <project> element and set the value attribute to the Java version you want to use
<property name="java.target" value="7" />
<property name="java.source" value="7" />
Building and deploying Kanzi applications to Android manually
SCons runs the SConstruct file in the configuration directory of the platform from which you run the scons
command. SConstruct file is the entry point for building the application and contains the information about the Kanzi Engine location and runs these files:
- <KanziWorkspace>/Engine/configs/platforms/common/config.py includes the Kanzi library definitions and common build flags used when building for all platforms.
- <KanziWorkspace>/Engine/configs/platforms/<PlatformName>/config.py includes the Kanzi platform-specific build flags and defines, and the toolchain. Edit this file when you want to customize the build configuration for your platform. For example, to match the locations of your platform SDK and board support package.
- <ProjectName>/Application/configs/platforms/common/config.py includes the optional, project-specific common configuration parameters.
- <ProjectName>/Application/configs/platforms/<PlatformName>/config.py includes the optional, project-specific platform configuration parameters.
To build and deploy Kanzi applications to Android manually:
-
If you add content to your application using the Kanzi Engine API, make sure to include that content in the <ProjectName>/configs/android/build.xml file in the
<target name="-pre-compile">
target. For example, to add all .xml and .png files in the <ProjectName>/Application/bin directory use
<target name="-pre-compile">
<echo>Copying assets</echo>
<copy todir="${asset.absolute.dir}">
<fileset dir="${asset.absolute.dir}/../../../../bin">
<include name="**/*.kzb"/>
<include name="**/*.cfg"/>
<include name="**/*.xml"/>
<include name="**/*.png"/>
- Connect your Android device to your computer.
-
Open the command line in the configuration directory of the platform for which you want to build the Kanzi application (<ProjectName>/Application/configs/platforms/<PlatformName>) and make sure you have the correct environmental variables set. See Setting the Kanzi environment variables.
For example, to build your Kanzi application for:- Android. Open the command line in the <ProjectName>/Application/configs/platforms/android directory.
- Linux. Open the command line in the <ProjectName>/Application/configs/platforms/linux_x11_glx_cpp98 directory.
- Windows. Open the command line in the <ProjectName>/Application/configs/platforms/win32 directory.
-
Run the
scons
command with the build parameters for your Kanzi application.Syntax | scons <library> <type> <name> |
Parameters | library | (Optional) the graphics library: ES2 builds the application with OpenGL ES 2.0GL builds the application with OpenGL
| type | (Optional) the build type: Release builds the application with compiler optimizations enabled. The release option builds smaller files than the debug option. Use this option for production purposes. Default value.Debug builds the application with disabled compiler optimizations and contains full debug information you can use with a debugger. The debug option builds larger files and debug applications run slower. Use this option for development purposes.Profiling builds the application with compiler optimizations enabled and links the application against the Profiling build. Use this option when you want to measure the performance of different parts of Kanzi Engine. For example, when you want to find out how much time Kanzi uses on different tasks during application startup, or which parts of the application take a lot of time to run. See Measuring application performance.
| name | (Optional) the name of the project |
|
Examples |
// Builds the application with the default settings as specified
// in config.py and SConstruct configuration files.
scons
// Builds the debug version of the application with
// the OpenGL graphics library.
scons GL debug
// Builds the debug version of the application with the
// OpenGL ES 2.0 graphics library from the Kanzi Studio
// project named MyProject.
scons ES2 debug MyProject |
Scons builds the Kanzi application source code and binary files in the <ProjectName>/Application/output directory.
- In the <ProjectName>/Application/output directory run
adb install
or ant release install
to install the .apk package of your Kanzi application on your Android device.
For example, if your project is called MyProject and is stored in the <KanziWorkspace> run:
adb install MyProject.apk
orant release install
Troubleshooting
- When deploying a Kanzi application to an Android device with a locked screen, running the application can fail or present wrong visual result. To get the correct result, restart the application.
-
When you receive this error while compiling Kanzi applications for Android:
[dex] Pre-Dexing C:\KanziWorkspace\3rdPartySDKs\android-sdk-windows\tools\support
\annotations.jar -> annotations-fa751cd593bf7078e9c18d47a485e852.jar
[dx] Error: Could not create the Java Virtual Machine.Error occurred during
initialization of VM
[dx] Error: A fatal exception has occurred. Program will exit.
[dx]
[dx] Could not reserve enough space for object heap
BUILD FAILED
Limit the max heap size of the dx tool in <KanziWorkspace>/3rdPartySDKs/android-sdk-windows/build-tools/18.1.0/dx.bat. Change the line:
set defaultXmx=
-Xmx1024M
to
set defaultXmx=-Xmx512M
- When using Java JDK version 1.8 or newer with Apache Ant version earlier than 1.9.0, Android build fails at Ant phase with the error message:
Class not found: javac1.8
To use JDK version 1.8 or newer with Apache Ant version earlier than 1.9.0, pass this flag to Ant:
-Dbuild.compiler=javac1.7
- When you receive this error while building Android package:
[javac] C:\KanziWorkspace\Projects\Myproject.java:142: error: binary literals are not supported in -source 1.5
[javac] private static int i = 0b10101;
[javac] ^
[javac] (use -source 7 or higher to enable binary literals)
[javac] 1 error
You must use a version of Java which supports binary literals. See Setting the Java version for Kanzi applications.
- When file paths in a project are longer than 260 characters, building of the Android .apk fails. To build the .apk, use a shorter name for your Kanzi project.
Building applications using the Kanzi Studio 3.6.4 Android platform package
The Kanzi 3.6.4 Android platform package extends the Kanzi installation and allows you to use Android Studio, the Clang toolchain, and the Gradle build system when developing Kanzi applications for Android.
This Android platform package is tested on Ubuntu/Linux 16.04.5, Ubuntu/Linux 18.04.1, and Windows 10.
Submit the request for the Kanzi 3.6.4 Android platform package using the Kanzi Support Portal at support.rightware.com.
Requirements
To build and deploy Kanzi applications to Android devices using the Kanzi 3.6.4 Android platform package, you need:
Installing the Android platform package
Extract the Android platform package zip file to the <KanziWorkspace> directory. When you extract the zip file, skip duplicate files instead of overwriting those files.
Setting up the build environment
After you install the Android platform package, set up your build environment.
To set up the build environment:
- Open Android Studio and in the welcome screen select Open an existing Android Studio project.
The Open File or Project window opens.
- In the Open File or Project window go to <KanziWorkspace>/Engine/applications/kzb_player/configs/platforms and select the android_gradle project.
- In Windows Explorer go to <KanziWorkspace>/Engine/applications/kzb_player and create a bin directory.
The kzb_player project contains C++ and Java source files which you can use as a starting point for your application. The build process combines those source files, packs the kzb and configuration files located in the bin directory into assets, and includes those assets in the Android package.
- In Kanzi Studio export the kzb file for your Kanzi application to the bin directory you created in the previous step. See Using kzb files.
- In the <KanziWorkspace>/Engine/applications/kzb_player/bin directory create a plain text file called binaries.cfg and in that file list the kzb files that your Kanzi application uses. Add the name of only one kzb file on each line.
For example:MyFirstProject.kzb
MySecondProject.kzb
- In Android Studio in the main menu select Build > Make Project to build the application package.
If you do not have the required Android SDK and NDK installed, Android Studio asks you whether you want to download and install them. If you install the Android SDK and NDK, repeat this step once the installation is complete.
By default Android Studio uses the debug build configuration. When you build the kzb_player project, you can find the Android package at <KanziWorkspace>/Engine/applications/kzb_player/configs/platforms/android_gradle/app/build/outputs/apk/debug.
To build using the release build configuration, open the Build Variants window and set the Build Variant to release.
- Deploy your Kanzi application to an Android device:
- Connect your Android device to your computer.
- In the Android Studio main menu select Run > Run 'app' to deploy your application.
Deploying a Kanzi application to Android Emulator
Before you can deploy a Kanzi application to Android Emulator, you need to set up the Android Emulator device. See https://developer.android.com/studio/run/emulator.
To deploy a Kanzi application to Android Emulator:
- In the Android Studio terminal run the
adb devices
command to check whether the ADB connection works correctly.
- In the Android Studio main menu select Run > Run 'app' to deploy your application.
Troubleshooting
- When you receive this error while building an Android package:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app.packageDebug'.
> Failed to obtain compression information for entry
Check that you are using Android Studio version 3.2. This error occurs on Android Studio version 3.1.
- When you receive this error while building an Android package:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app.packageDebug'.
> Java heap space
Increase the available heap amount in the gradle. For example, in Android Studio in the android_gradle project open the gradle.properties file and set:
org.gradle.jvmargs=-Xmx3536m
- When you receive this error while deploying your Kanzi project to Android Emulator:
Installation failed with message Failed to finalize session:
INSTALL_FAILED_INSUFFICIENT_STORAGE.
In Android Studio:
- Set the Build Variant to release
- In the android_gradle project open the kanzi.properties file and set:
arch=x86
See also
Installing the Kanzi build environment for Android
Building Kanzi applications for Android using a script
Installing the Kanzi build environment manually
Tutorial: Create a simple in-vehicle infotainment application
Android OEM USB Drivers
Deploying Kanzi applications
Open topic with navigation